﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Myblog : System.Web.UI.Page
{
    chodientuDataContext db = new chodientuDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"] == null)
        {
            Response.Redirect("chuadangnhap.aspx");
        } 
        showBLog();
    }
    private void showBLog()
    { 
        var query  = from bv in db.Baiviets
                     from bl in db.Nhatkies
                     where bv.Mablog == bl.Mablog && bl.Username == Session["user"].ToString()
                     select new {bv.Mabaiviet,bv.Ngaydang,bv.Quyenriengtu,bv.Noidung,bv.Tieude};
        GridView1.DataSource = query;
        GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Int32 id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
        Response.Write("<script>alert('"+id+"');</script>");
        var query = db.Baiviets.Where(n=>n.Mabaiviet.Equals(id)).First();
        db.Baiviets.DeleteOnSubmit(query);
        db.SubmitChanges();
        Response.Redirect(Request.RawUrl);
    }
}